<template>
  <view>
    <l-form-cell v-model="form.licenceNo" label="驾驶证号" :disabled="disabled" :must="type == 2" placeholder="请输入驾驶证号" />
    <l-form-cell label="准驾车型" has-slot icon-type="enter" :arrow="!disabled" :must="type == 2" @click="changeLicenceType">
      <view class="form-item flex-row flex-item align-center justify-end">
        <text class="text-30" :class="['color-t' + (form.licenceType ? 1 : 3)]">{{ form.licenceType || '请选择准驾车型' }}</text>
      </view>
    </l-form-cell>
    <l-form-cell label="驾驶证初次领证日期" has-slot label-width="290rpx" :arrow="!disabled" :must="type == 2" @click="changeDate('issueDate')">
      <view class="form-item flex-row flex-item align-center justify-end">
        <text class="text-30" :class="['color-t' + (form.issueDate ? 1 : 3)]">{{ form.issueDate || '请选择日期' }}</text>
      </view>
    </l-form-cell>
    <l-form-cell label="驾驶证有效截止日期" has-slot label-width="290rpx" :arrow="!disabled" :must="type == 2" @click="changeDate('validEndDate')">
      <view class="form-item flex-row flex-item align-center justify-end">
        <text class="text-30" :class="['color-t' + (form.validEndDate ? 1 : 3)]">{{ form.validEndDate || '请选择日期' }}</text>
      </view>
    </l-form-cell>
    <l-form-cell label="从业资格证有效期至" has-slot label-width="290rpx" :arrow="!disabled" :must="type == 2" unlined @click="changeDate('certificationValidDateEnd')">
      <view class="form-item flex-row flex-item align-center justify-end">
        <text class="text-30" :class="['color-t' + (form.certificationValidDateEnd ? 1 : 3)]">{{ form.certificationValidDateEnd || '请选择日期' }}</text>
      </view>
    </l-form-cell>
  </view>
</template>

<script>
export default {
  name: 'IdentityInfoModel',
  props: {
    type: {
      type: [String, Number],
      default: 0
    },
    data: {
      type: Object,
      default: () => {}
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      form: {
        licenceNo: '',
        licenceType: '',
        issueDate: '',
        validEndDate: '',
        certificationValidDateEnd: ''
      }
    }
  },
  watch: {
    data: {
      handler(e) {
        Object.keys(this.form).forEach(item => {
          this.form[item] = e[item]
        })
      },
      deep: true
    },
    form: {
      handler(newVal) {
		  if(newVal.validEndDate == '2999-12-31'){
			  this.form.validEndDate = '长期'
			  console.log(newVal.validEndDate)
		  }
        this.$emit('update', this.form)
      },
	  immediate:true,
      deep: true
    }
  },
  methods: {
    // 修改日期
    changeDate(attr) {
      if (this.disabled) return
      this.$emit('changeDate', attr)
    },
    // 修改准驾车型
    changeLicenceType() {
      if (this.disabled) return
      this.$emit('changeLicenceType')
    }
  }
}
</script>

<style scoped>

</style>
